package com.dzu.medium;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoDong
 * @date 2023/2/1 10:00
 * @description 633. 平方数之和
 */
public class Test633 {
    public static void main(String[] args) {

        System.out.println(judgeSquareSum2(5));
    }


    public static boolean judgeSquareSum(int c) {

        for (long a = 0; a * a <= c; a++) {
            double b = Math.sqrt(c - a * a);
            if (b == (int) b) {
                return true;
            }
        }
        return false;

    }

    public static boolean judgeSquareSum2(int c) {
        Map<Long, Long> map = new HashMap<>();

        for (long a = 0; a * a <= c; a++) {
            map.put(a * a, a);
        }
        for (Long key : map.keySet()) {
            Long value = map.get(c - key);
            if (value != null) {
                return true;
            }
        }
        return false;

    }
}
